<?php 
class User{
	private $mobile;
	private $password;
	private $confirmPassword;
	private $db;

	public function __construct($db){
		$this->db = $db;
	}
	public function userLogin(){
		$res= array("msg"=>"手机号码或密码错误！","status"=>104,"data"=>"");
		$sql="select * from user where username='{$this->mobile}' and pwd='{$this->password}'";
		$row=$this->db->selectRow($sql);
		if($row){
			$res= array("msg"=>"登陆成功！","status"=>105,"data"=>"");
			$_SESSION['mobile']=$this->mobile;
			$_SESSION['shopCart']=session_id();
			$_SESSION['uid']=$row['userId'];
		}
		return $res;
	}
	public function userQuickLogin(){
		$res= array("msg"=>"手机号码错误！","status"=>104,"data"=>"");
		$sql="select * from user where username='{$this->mobile}'";
		$row=$this->db->selectRow($sql);
		if($row){
			$res= array("msg"=>"登陆成功！","status"=>105,"data"=>"");
			$_SESSION['mobile']=$this->mobile;
			$_SESSION['shopCart']=session_id();
			$_SESSION['uid']=$row['userId'];			
		}
		return $res;
	}	
	public function loginInfoCheck(){
		$this->mobile=$_GET['mobile'];
		$this->password=$_GET['password'];
		if(strlen($this->mobile)<1){return array("msg"=>"请输入手机号码！","status"=>100,"data"=>"");exit;}
		if(strlen($this->password)<1){return array("msg"=>"请输入密码！","status"=>101,"data"=>"");exit;}
	}
	public function quickLoginInfoCheck(){
		$this->mobile=$_GET['mobile'];
		if(strtolower($_GET['verificationCode'])!=strtolower($_SESSION['code'])){return array("msg"=>"验证码错误！","status"=>100,"data"=>"");exit;}
		if(strlen($this->mobile)<1){return array("msg"=>"请输入手机号码！","status"=>100,"data"=>"");exit;}
	}
	public function userReg(){
		$res= array("msg"=>"注册失败！","status"=>104,"data"=>"");
		$time=time();
		$sql="insert into user(username,pwd,time) values('{$this->mobile}','{$this->password}','{$time}')";
		if($this->db->otherData($sql)>0){
			$res= array("msg"=>"注册成功！","status"=>105,"data"=>"");
		}
		return $res;
	}

	public function regInfoCheck(){
		$this->mobile=$_GET['mobile'];
		$this->password=$_GET['password'];
		$this->confirmPassword=$_GET['confirmPassword'];
		if(strtolower($_GET['verificationCode'])!=strtolower($_SESSION['code'])){return array("msg"=>"验证码错误！","status"=>100,"data"=>"");exit;}
		if(strlen($this->mobile)<1){return array("msg"=>"请输入手机号码！","status"=>100,"data"=>"");exit;}
		if(strlen($this->password)<1){return array("msg"=>"请输入密码！","status"=>101,"data"=>"");exit;}
		if(strlen($this->confirmPassword)<1){return array("msg"=>"请输入确认密码！","status"=>102,"data"=>"");exit;}
		if($this->password != $this->confirmPassword){return array("msg"=>"两次输入密码不一致！","status"=>103,"data"=>"");exit;}
	}

	public function userOut(){
		$_SESSION=array();
		setcookie(session_name(),'',time()-1,'/');
		session_destroy();
		return true;
	}
}
	
 ?>